package com.zj.study.pojo.model;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.apache.commons.collections4.CollectionUtils;

/**
 * <p>
 *   树形节点类BeanTreeNode
 *   每一个节点对应一个实体，节点包含了实体信息，为了保证实体之间的关联关系，需要留有父节点信息，
 *   所有的子节点信息。由此推断出，节点的主要成员有
 *  <ui>
 *    <li>父节点信息</li>
 *    <li>所有子节点信息</li>
 *    <li>当前实体信息</li>
 *  </ui>
 * <p/>
 *
 * @author 赵赳
 * @since 2021/12/14 9:56
 */
public class BeanTreeNode {

  /**标识id*/
  private String id;

  /**父id标识，为了方便获取冗余出来*/
  private String pid;

  /**父节点*/
  private BeanTreeNode parentNode;

  /**节点类型*/
  private String nodeType;

  /**节点值*/
  private Object bean;

  /**子节点*/
  private List<BeanTreeNode> childNodes;


  /**
   * @param parentNode 父节点
   * @param nodeType 子节点
   * @param bean 对象实体
   */
  public BeanTreeNode(BeanTreeNode parentNode, String nodeType, Object bean) {
    this.parentNode = parentNode;
    this.nodeType = nodeType;
    this.bean = bean;
    this.childNodes = new ArrayList<BeanTreeNode>();
    this.id = UUID.randomUUID().toString().replaceAll("-", "");
    if (parentNode != null) {
      this.pid = parentNode.getId();
    }
  }

  /**
   * @return the nodeType
   */
  public String getNodeType() {
    return nodeType;
  }

  /**
   * @param nodeType the nodeType to set
   */
  public void setNodeType(String nodeType) {
    this.nodeType = nodeType;
  }

  /**
   * @return the parentNode
   */
  public BeanTreeNode getParentNode() {
    return parentNode;
  }

  /**
   * @param parentNode the parentNode to set
   */
  public void setParentNode(BeanTreeNode parentNode) {
    this.parentNode = parentNode;
  }

  /**
   * @return the bean
   */
  public Object getBean() {
    return bean;
  }

  /**
   * @param bean the bean to set
   */
  public void setBean(Object bean) {
    this.bean = bean;
  }

  /**
   * @return the childNodes
   */
  public List<BeanTreeNode> getChildNodes() {
    return childNodes;
  }

  /**
   * @param childNodes the childNodes to set
   */
  public void setChildNodes(List<BeanTreeNode> childNodes) {
    this.childNodes = childNodes;
  }

  /**
   * @return the id
   */
  public String getId() {
    return id;
  }

  /**
   * @param id the id to set
   */
  public void setId(String id) {
    this.id = id;
  }

  /**
   * @return the pid
   */
  public String getPid() {
    return pid;
  }

  /**
   * @param pid the pid to set
   */
  public void setPid(String pid) {
    this.pid = pid;
  }

  /**
   * 是否具有子节点
   * @return true or false
   */
  public boolean haveChild() {
    return !CollectionUtils.isEmpty(childNodes);
  }



}
